<?php
$goodsId = (float)$_REQUEST['id'];
if($goodsId < 1){
    exit;
}
define('GOODS_ID',$goodsId);
require dirname(__FILE__).'/core/fanwe.php';
$fanwe = &FanweService::instance();
$fanwe->cache_list = array('business');
$fanwe->is_session = false;
$fanwe->is_user = false;
$fanwe->is_cron = false;
$fanwe->is_misc = false;
$fanwe->initialize();
$goods = FDB::fetchFirst('SELECT * FROM '.FDB::table('goods').' WHERE id = '.GOODS_ID);
if(!$goods){
	exit;
}
$goodsId = str_replace("taobao_","",$goods['keyid']);
?><html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title><?php echo $_FANWE['setting']['site_name']; ?></title>
</head>
<body>
<div style="visibility:hidden; height:230px; overflow:hidden;">
    <a id="tdjLink" href="<?php echo $goods['url'] ?>" biz-itemid="<?php echo $goodsId; ?>" data-style="2" data-rd="1" data-tmpl="230x312" data-type="0"><?php echo $goods['name'] ?></a>
</div>
<div style="text-align:center;">
	<img src="/loading.gif" />
</div>
</body>
<script type="text/javascript">
(function(win,doc){
    var s = doc.createElement("script"), h = doc.getElementsByTagName("head")[0];
    if (!win.alimamatk_show) {
        s.charset = "gbk";
        s.async = true;
        s.src = "http://a.alimama.cn/tkapi.js";
        h.insertBefore(s, h.firstChild);
    };
    var o = {
        pid: "<?php echo $_FANWE['cache']['business']['taobao']['tk_pid']; ?>",
        appkey:"<?php echo $_FANWE['cache']['business']['taobao']['app_key']; ?>"
    };
    win.alimamatk_onload = win.alimamatk_onload || [];
    win.alimamatk_onload.push(o);
})(window,document);

var GET_URL;
var intervalCount = 0;
function getUrl(){
    if(window.frames.length > 0 && window.frames["writeable_iframe_0"]){
        var iframe = window.frames["writeable_iframe_0"];
        var doc = iframe.contentDocument || iframe.document;
        var links = doc.getElementsByTagName("A");
        if(links && links.length > 1){
            var link = links[1].href;
            if(link && link != undefined){
                clearInterval(GET_URL);
                location.href = link;
            }
        }
    }
	if(intervalCount > 20){
		location.href = "<?php echo $goods['url'] ?>";
	}
	intervalCount++;
};
GET_URL = setInterval(getUrl,500);
</script>
</html>